package com.jueyunqi.app;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSONObject;
import com.jueyunqi.dao.User;
import com.jueyunqi.dao.UserDAO;

public class App
{
	private final static App app = new App();
	private ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
	
	public static void main(String[] args)
	{
		app.jRedis();
	}
	
	private void springRedis(){
		UserDAO userDAO = applicationContext.getBean(UserDAO.class);
		User user = new User();
		user.setId(2);
		user.setName("obama2");
		userDAO.saveUser(user);
		
		User ret = userDAO.getUser(1);
		System.out.println(ret.getName());
	}
	
	private void jRedis(){
		UserDAO userDAO = applicationContext.getBean(UserDAO.class);
		User user = new User();
		user.setId(3);
		user.setName("jRedis3");
		userDAO.saveUser(user);
		
		User ret = userDAO.getUser(3);
		System.out.println(JSONObject.toJSON(ret));
	}
}
